<?php
class Faqs_Controller extends Template_Controller {

	public $template = 'client/index';
	protected $mlist;
    public function __construct()
    {
        parent::__construct();
        
        //Css
        $this->template->css = $this->site['theme_url'].'faqs/faqs.css';
        //View
        $this->get_view();
    }
    
	public function __call($method, $arguments)
	{
		// Disable auto-rendering
		$this->auto_render = FALSE;
	}
	
    public function index()
    {	
    	 $this->show_list();
    	 
		
    }
    public function _show()
	{
		$language=$this->get_client_lang();
		$model = new Faqs_content_Model(); 
		$mlist = $model->get_faqs($language);
		return $mlist;
	}
    public function show_list()
    {
    	
		$this->template->content = new View('faqs/index');
    	$this->template->left = new View('client/left');
    	//$this->where_sql();
		
		//Pagination
    	$this->pagination = new Pagination(array(
    		'base_url'    => 'faqs/search/',
		    'uri_segment'    => 'page',
		    'total_items'    => ORM::factory('faqs')->count_all(),
		    'items_per_page' => $this->site['site_num_line2'],
		    'style'          => 'classic',
		));
		$this->db->limit($this->pagination->items_per_page,$this->pagination->sql_offset);
    	
    	//$this->where_sql();
    	$mlist = $this->_show();
    	
    	$this->template->content->mlist = $mlist;
    	    	
    }
    
    public function detail($id)
    {	
    	$this->template->content = new View('faqs/detail');
  		$this->template->left = new View('client/left');
		$mlist = $this->_show();
    	$this->template->content->mlist = $mlist;
   		$language=$this->get_client_lang();
		$model = new Faqs_content_Model(); 
		$mr = $model->get($id,$language);
    	$this->template->content->mr =$mr[0];
    	
    	$mlist = $this->_show();
    	for($i=0;$i<count($mlist);$i++){
    		$mlist[$i]['faqs_content'] = $this->cut_string(30,$mlist[$i]['faqs_content']);
    	}
    	$this->template->content->mlist = $mlist;
    }
    public function cut_string($number,$string)
    {
    	$substr='';
		$arrString = explode(' ',$string);
		for($i=0;$i<$number;$i++){
			if($i<count($arrString))
			$substr = $substr.$arrString[$i].' ';
		}    	
    	return $substr;
    }
}
?>